from tkinter import Tk
from tkinter import ttk
from database.table import tablee
from database.table.tablee import Employ

def CountEmploy():
    count_employ_screen = Tk()
    count_employ_screen.title('统计员工信息')
    screen_width, screen_height = count_employ_screen.maxsize()
    # 窗口的宽和高
    width = 605
    height = 200
    centre = '%dx%d+%d+%d' % (width, height, (screen_width - width) / 2,
                              (screen_height - height) / 2)
    count_employ_screen.geometry(centre)
    count_employ_screen.resizable(0,0)

    employee = tablee.session.query(Employ).all()
    data = Employ.to_json(employee)
    length = len(data)

    tree = ttk.Treeview(count_employ_screen)  #创建表格对象
    tree["columns"] =("编号","姓名","密码","级别","电话","工资","备注")
    tree.column("编号", width=50)  # 设置列
    tree.column("姓名", width=50)
    tree.column("密码", width=50)
    tree.column("级别", width=50)
    tree.column("电话", width=100)
    tree.column("工资", width=50)
    tree.column("备注", width=50)
    tree.heading("编号", text="编号")  # 显示表头名
    tree.heading("姓名", text="姓名")
    tree.heading("密码", text="密码")
    tree.heading("级别", text="级别")
    tree.heading("电话", text="电话")
    tree.heading("工资", text="工资")
    tree.heading("备注", text="备注")

    j = length - 1

    for i in range(0, length):
        num = data[j]['Eno']
        name = data[j]['Ename']
        password = data[j]['Epassword']
        level = data[j]['Elevel']
        phone = data[j]['Ephone']
        pay = data[j]['Epay']
        remarks = data[j]['Eremarks']
        tree.insert("", 0, text='', value=(num, name, password, level, phone, pay, remarks))
        j = j -1
    tree.pack()

    tablee.session.close()

    count_employ_screen.mainloop()

if __name__ == '__main__':
    CountEmploy()